﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using DatingWebSite.DatingService;

namespace DatingWebSite.Pages
{
    public partial class EditPersonalInfo : System.Web.UI.Page
    {
        protected int ProfileId = 0;

        protected int TenantID = 1;

        protected string strDate = string.Empty;
        //ProfileId =Convert.ToInt32(Session["MemberProfileID"]);
        //TenantID =Convert.ToInt32(Session["TenentID"]);
        //ContentFetch.ContentFetch obj = new ContentFetch.ContentFetch();
        //ContentFetch.MemberProfile objPersonalInfo = obj.MemberProfileSelect(Session["MemberProfileID"], Session["TenentID"], "007");



        protected void Page_Load(object sender, EventArgs e)
        {
            //Session.Add("MemberProfileID");
            //ProfileId1 = Session["MemberProfileID"];
            ProfileId = Convert.ToInt32(Session["MemberProfileID"]);
            TenantID = Convert.ToInt32(Session["TenentID"]);

            //ViewState["ObjProfileInfo"] = objPersonalInfo;
            DatingService.DatingService obj = new DatingService.DatingService();
            DatingService.MemberProfile objPersonalInfo = obj.MemberProfileSelect(ProfileId, TenantID, "007");


            //ViewState["PersonalInfo"] = objPersonalInfo;
            // Session.Add("ProfileInfo", objPersonalInfo);

            if (!IsPostBack)
            {
                int heightID = Convert.ToInt32(ConfigurationManager.AppSettings.Get("Height"));
                int generalBuildID = Convert.ToInt32(ConfigurationManager.AppSettings.Get("GeneralBuild"));
                int hairColorID = Convert.ToInt32(ConfigurationManager.AppSettings.Get("HairColor"));
                int eyeColorID = Convert.ToInt32(ConfigurationManager.AppSettings.Get("EyeColor"));
                int ethnicityID = Convert.ToInt32(ConfigurationManager.AppSettings.Get("Ethnicity"));
                int SmokingPreferenceID = Convert.ToInt32(ConfigurationManager.AppSettings.Get("SmokingPreference"));
                int looksID = Convert.ToInt32(ConfigurationManager.AppSettings.Get("Looks"));
                int occupationID = Convert.ToInt32(ConfigurationManager.AppSettings.Get("Occupation"));
                int incomeID = Convert.ToInt32(ConfigurationManager.AppSettings.Get("Income"));
                int RelationshipID = Convert.ToInt32(ConfigurationManager.AppSettings.Get("RelationshipExpectation"));
                int MaritalStatusID = Convert.ToInt32(ConfigurationManager.AppSettings.Get("MaritalStatus"));
                int NoOfChildrenID = Convert.ToInt32(ConfigurationManager.AppSettings.Get("NumberOfChildren"));
                int LivingAtHomeID=Convert.ToInt32(ConfigurationManager.AppSettings.Get("LivingAtHome"));
                int religionID = Convert.ToInt32(ConfigurationManager.AppSettings.Get("Religion"));
                int petID = Convert.ToInt32(ConfigurationManager.AppSettings.Get("Pet"));
                strDate = Convert.ToString(objPersonalInfo.DOB);
 
                

                string strMonth = strDate.Substring(0, 2);
                string strDay = strDate.Substring(4, 2);
                string strYear = strDate.Substring(8, 4);

                if (objPersonalInfo.DOB != null)
                {
                    drpMonth.SelectedItem.Text = strMonth;
                    drpDay.SelectedItem.Text = strDay;
                    drpYear.SelectedItem.Text = strYear;
                }



                //ContentFetch.ContentFetch obj = new ContentFetch.ContentFetch();
                // ContentFetch.MemberProfile objPersonalInfo = obj.MemberProfileSelect(ProfileId, TenantID, "007");


                // ProfileId1 = objPersonalInfo.UserName;

                DatingService.EntityValue[] objHeightList = obj.EntityValueSelectAllByEntityID(heightID, 1, "");
                ddlHeight.DataSource = objHeightList;
                ddlHeight.DataTextField = "EntityVal";
                ddlHeight.DataValueField = "EntityValueID";
                ddlHeight.DataBind();
                if (objPersonalInfo.Height != string.Empty)
                    //ddlHeight.SelectedItem.Value = "EntityValueID"; 
                ddlHeight.SelectedItem.Text = objPersonalInfo.Height;
               
         
                //ddlHeight.DataBind();


                DatingService.EntityValue[] objGeneralBuildList = obj.EntityValueSelectAllByEntityID(generalBuildID, 1, "");
                ddlGeneralBuild.DataSource = objGeneralBuildList;
                ddlGeneralBuild.DataTextField = "EntityVal";
                ddlGeneralBuild.DataValueField = "EntityValueID";
                ddlGeneralBuild.DataBind();
                if (objPersonalInfo.GeneralBuild != string.Empty)
                    //ddlGeneralBuild.SelectedItem.Text = objPersonalInfo.GeneralBuild;
                //ddlGeneralBuild.SelectedItem.Value = objPersonalInfo.GeneralBuild;
                ddlGeneralBuild.SelectedItem.Text = objPersonalInfo.GeneralBuild;
                //ddlGeneralBuild.DataBind();


                DatingService.EntityValue[] objHairColorList = obj.EntityValueSelectAllByEntityID(hairColorID, 1, "");
                ddlHairColor.DataSource = objHairColorList;
                ddlHairColor.DataTextField = "EntityVal";
                ddlHairColor.DataValueField = "EntityValueID";
                ddlHairColor.DataBind();
                if (objPersonalInfo.HairColor != string.Empty)
                    ddlHairColor.SelectedItem.Text = objPersonalInfo.HairColor;
                //ddlHairColor.DataBind();

                DatingService.EntityValue[] objEyeColorList = obj.EntityValueSelectAllByEntityID(eyeColorID, 1, "");
                ddlEyecolor.DataSource = objEyeColorList;
                ddlEyecolor.DataTextField = "EntityVal";
                ddlEyecolor.DataValueField = "EntityValueID";
                ddlEyecolor.DataBind();
                if (objPersonalInfo.EyeColor != string.Empty)
                    ddlEyecolor.SelectedItem.Text = objPersonalInfo.EyeColor;
                //ddlEyecolor.DataBind();

                DatingService.EntityValue[] objEthnicityList = obj.EntityValueSelectAllByEntityID(ethnicityID, 1, "");
                ddlEthnicity.DataSource = objEthnicityList;
                ddlEthnicity.DataTextField = "EntityVal";
                ddlEthnicity.DataValueField = "EntityValueID";
                ddlEthnicity.DataBind();
                if (objPersonalInfo.Ethnicity != string.Empty)
                    ddlEthnicity.SelectedItem.Text = objPersonalInfo.Ethnicity;
                //ddlEthnicity.DataBind();

                DatingService.EntityValue[] objSmokingPreference = obj.EntityValueSelectAllByEntityID(SmokingPreferenceID, 1, "");
                ddlSmoke.DataSource = objSmokingPreference;
                ddlSmoke.DataTextField = "EntityVal";
                ddlSmoke.DataValueField = "EntityValueID";
                ddlSmoke.DataBind();
                if (objPersonalInfo.SmokingPreference != string.Empty)
                    ddlSmoke.SelectedItem.Text = objPersonalInfo.SmokingPreference;
                //ddlSmoke.DataBind();

                DatingService.EntityValue[] objlooksList = obj.EntityValueSelectAllByEntityID(looksID, 1, "");
                ddlLooks.DataSource = objlooksList;
                ddlLooks.DataTextField = "EntityVal";
                ddlLooks.DataValueField = "EntityValueID";
                ddlLooks.DataBind();
                if (objPersonalInfo.Looks != string.Empty)
                    ddlLooks.SelectedItem.Text = objPersonalInfo.Looks;
                //ddlLooks.DataBind();

                DatingService.EntityValue[] objOccupationList = obj.EntityValueSelectAllByEntityID(occupationID, 1, "");
                ddlOccupations.DataSource = objOccupationList;
                ddlOccupations.DataTextField = "EntityVal";
                ddlOccupations.DataValueField = "EntityValueID";
                ddlOccupations.DataBind();
                if (objPersonalInfo.Occupation != string.Empty)
                    ddlOccupations.SelectedItem.Text = objPersonalInfo.Occupation;
                //ddlOccupations.DataBind();

                DatingService.EntityValue[] objIncomeList = obj.EntityValueSelectAllByEntityID(incomeID, 1, "");
                ddlIncome.DataSource = objIncomeList;
                ddlIncome.DataTextField = "EntityVal";
                ddlIncome.DataValueField = "EntityValueID";
                ddlIncome.DataBind();
                if (objPersonalInfo.Income != string.Empty)
                    ddlIncome.SelectedItem.Text = objPersonalInfo.Income;
                //ddlIncome.DataBind();

                DatingService.EntityValue[] objRelationship = obj.EntityValueSelectAllByEntityID(RelationshipID, 1, "");
                ddlRelationship.DataSource = objRelationship;
                ddlRelationship.DataTextField = "EntityVal";
                ddlRelationship.DataValueField = "EntityValueID";
                ddlRelationship.DataBind();
                if (objPersonalInfo.RelationshipExpectation != string.Empty)
                    ddlRelationship.SelectedItem.Text = objPersonalInfo.RelationshipExpectation;
                //ddlRelationship.DataBind();

                DatingService.EntityValue[] objMaritalStatus = obj.EntityValueSelectAllByEntityID(MaritalStatusID, 1, "");
                ddlMaritalStatus.DataSource = objMaritalStatus;
                ddlMaritalStatus.DataTextField = "EntityVal";
                ddlMaritalStatus.DataValueField = "EntityValueID";
                ddlMaritalStatus.DataBind();
                if (objPersonalInfo.MartialStatus != string.Empty)
                    ddlMaritalStatus.SelectedItem.Text = objPersonalInfo.MartialStatus;
                //ddlMaritalStatus.DataBind();


                DatingService.EntityValue[] objNoOfChildren = obj.EntityValueSelectAllByEntityID(NoOfChildrenID, 1, "");
                ddlChildren.DataSource = objNoOfChildren;
                ddlChildren.DataTextField = "EntityVal";
                ddlChildren.DataValueField = "EntityValueID";
                ddlChildren.DataBind();
                if (objPersonalInfo.NumberOfChildren != string.Empty)
                    ddlChildren.SelectedItem.Text = objPersonalInfo.NumberOfChildren;
                //ddlChildren.DataBind();

                DatingService.EntityValue[] objLivingAtHome = obj.EntityValueSelectAllByEntityID(LivingAtHomeID, 1, "");
                ddlLivingAtHome.DataSource = objLivingAtHome;
                ddlLivingAtHome.DataTextField = "EntityVal";
                ddlLivingAtHome.DataValueField = "EntityValueID";
                ddlLivingAtHome.DataBind();
                if (objPersonalInfo.LivingAtHome != string.Empty)
                    ddlLivingAtHome.SelectedItem.Text = objPersonalInfo.LivingAtHome;
                //ddlLivingAtHome.DataBind();

                DatingService.EntityValue[] objReligionList = obj.EntityValueSelectAllByEntityID(religionID, 1, "");
                ddlReligion.DataSource = objReligionList;
                ddlReligion.DataTextField = "EntityVal";
                ddlReligion.DataValueField = "EntityValueID";
                ddlReligion.DataBind();
                if (objPersonalInfo.Religion != string.Empty)
                    ddlReligion.SelectedItem.Text = objPersonalInfo.Religion;
                //ddlReligion.DataBind();

                DatingService.EntityValue[] objPetList = obj.EntityValueSelectAllByEntityID(petID, 1, "");
                ddlPet.DataSource = objPetList;
                ddlPet.DataTextField = "EntityVal";
                ddlPet.DataValueField = "EntityValueID";
                ddlPet.DataBind();
                if (objPersonalInfo.Pet != string.Empty)
                    ddlPet.SelectedItem.Text = objPersonalInfo.Pet;
                //ddlPet.DataBind();

                
               
                
               
               
               
            }


        }

        protected void ddlHeight_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void btnModify_Click(object sender, EventArgs e)
        {
            try
            {
                //Edit profile. 
                DatingService.MemberProfile objProfile = new DatingService.MemberProfile();
                DatingService.DatingService obj = new DatingService.DatingService();
                DatingService.MemberProfile objPersonalInfo = obj.MemberProfileSelect(ProfileId, TenantID, "007");
                //ob

                // objProfile = (ContentUpdate.MemberProfile)objPersonalInfo;

                objProfile.ProfileID = ProfileId;

                //objProfile = ViewState["PersonalInfo"]; 
                objProfile.UserName = Convert.ToString(Session["UserName"]);
                objProfile.Passwrd = objPersonalInfo.Passwrd;
                // objProfile.Passwrd=objPersonalInfo.pa
                //objProfile.ProfileID =Convert.ToInt32(Session["MemberProfileID"]);
                objProfile.Height = ddlHeight.SelectedItem.Text;
                objProfile.GeneralBuild = ddlGeneralBuild.SelectedItem.Text;
                objProfile.HairColor = ddlHairColor.SelectedItem.Text;
                objProfile.EyeColor = ddlEyecolor.SelectedItem.Text;
                objProfile.Ethnicity = ddlEthnicity.SelectedItem.Text;
                objProfile.SmokingPreference = ddlSmoke.SelectedItem.Text;
                objProfile.Looks = ddlLooks.SelectedItem.Text;

                objProfile.Occupation = ddlOccupations.SelectedItem.Text;
                objProfile.Income = ddlIncome.SelectedItem.Text;
                objProfile.RelationshipExpectation = ddlRelationship.SelectedItem.Text;
                objProfile.MartialStatus = ddlMaritalStatus.SelectedItem.Text;
                objProfile.LivingAtHome = ddlLivingAtHome.SelectedItem.Text;
                objProfile.Religion = ddlReligion.SelectedItem.Text;
                objProfile.Pet = ddlPet.SelectedItem.Text;

                DateTime Dob;
                DateTime.TryParse((drpMonth.Text + "/" + drpDay.Text + "/" + drpYear.Text).ToString(), out Dob);
                objProfile.DOB = Dob;
                objProfile.CreatedOn = DateTime.Today;
                objProfile.LastLoginOn = DateTime.Today;
                objProfile.TenantID = Convert.ToInt32(Session["TenentID"]);


                DatingService.DatingService objUpdate = new DatingService.DatingService();
                int MemberProfile = objUpdate.MemberProfileUpdate(objProfile, "007");
                if (MemberProfile <= 0)
                {
                    lblErrMessage.Text = "Your Profile Got updated";
                }
                else
                {
                    lblErrMessage.Text = " There was an error Updating profile. Please contact administrator";
                }


            }


            catch (Exception err)
            {
                lblErrMessage.Text = " There was an error Updating profile. Please contact administrator";
            }

        }

    }

}